Helpful Information
 
 
Category: Beginner
Beginner --> Appending string to DOM document.form.input(appendhere).value

Hi all,

I'm new to Javascript, and having a little trouble figuring out how to append strings to DOM assignments.

To be specific:

var appendhere = 'firstfield';
document.form.input(want to put 'appendhere' in here).value = myvalue;

I want to be read as "document.form.inputfirstfield.value". I'm guessing there's a simple solution for this, but unfortunately google doesn't seem to be of any help. "input+appendhere" outputs literally as document.form.input+appendhere.value.

Any help appreciated - many thanks.

- SuperGrover

I am not too clear as to what you are trying to achieve, but this may help you:-




<input type = "text" name = "inputfirstfield" id = "inputfirstfield">

<script type = "text/javascript">
var myvalue = "abcdefgh";
var appendhere = 'firstfield';
var x = "input"+ appendhere;
document.getElementById(x).value = myvalue;
</script>


Q. If you were to spell out numbers, how far would you have to go until you would find the letter "A"?
A. One thousand










privacy (GDPR)